import cpfFormulaTypeEnum, { cpfFormulaType } from '@/pages/SalaryManage/enum/cpfFormulaTypeEnum';
import feedbackReceiveEnum, { feedbackReceiveStatus } from './feedbackReceiveEnum';
import feedbackHandleEnum, { feedbackHandleStatus } from './feedbackHandleEnum';
import feedbackProblemTypeEnum, { feedbackProblemType } from './feedbackProblemTypeEnum';
import feedbackAssignTypeEnum, { feedbackAssignType } from './feedbackAssignTypeEnum';
import feedbackAutoAssignTypeEnum, { feedbackAutoAssignType } from './feedbackAutoAssignTypeEnum';
import feedbackBusiTypeEnum, { feedbackBusiType } from './feedbackBusiTypeEnum';
import addMinusStatusEnum from './addMinusStatusEnum';
import customInsuranceEnum from './customInsuranceEnum';
import housePlaceEnum from './housePlaceEnum';
import jobStatusEnum from './jobStatusEnum';
import socialTypeEnum, { socialTypeStatus } from './socialTypeEnum';
import insuranceFundFileProcessStatusEnum, {
    insuranceFundFileProcessStatus
} from './insuranceFundFileProcessStatusEnum';
import insuranceFundFileSocialStatusEnum, { insuranceFundFileSocialStatus } from './insuranceFundFileSocialStatusEnum';
import logBusiUnitEnum, { logBusiUnit } from './logBusiUnitEnum';
import decimalTypeEnum, { decimalTypeStatus } from './decimalTypeEnum';
import insuranceBaseTypeEnum, { baseTypeStatus } from './insuranceBaseTypeEnum';
import cpfSubmissionStatusEnum, { cpfSubmissionStatus } from './cpfSubmissionStatusEnum';
import sexEnum from './sexEnum';

[
    addMinusStatusEnum,
    customInsuranceEnum,
    housePlaceEnum,
    sexEnum,
    jobStatusEnum,
    socialTypeEnum,
    insuranceFundFileProcessStatusEnum,
    insuranceFundFileSocialStatusEnum,
    feedbackReceiveEnum,
    feedbackHandleEnum,
    feedbackProblemTypeEnum,
    feedbackAssignTypeEnum,
    feedbackAutoAssignTypeEnum,
    feedbackBusiTypeEnum,
    logBusiUnitEnum,
    insuranceBaseTypeEnum,
    decimalTypeEnum,
    cpfSubmissionStatusEnum,
    cpfFormulaTypeEnum
].forEach(enumModel => {
    const originEnum = { ...enumModel };
    Object.assign(enumModel, {
        /**
         * 根据枚举的key,获得相应key的显示值
         * @param key
         * @returns {string}
         */
        getShowName(key) {
            const enumItem = enumModel[key];

            if (enumItem) {
                return enumItem?.text;
            }

            if (!enumItem && key) {
                return `${key}`;
            }

            return '';
        }
    });

    if (!enumModel.hasOwnProperty('list')) {
        /**
         * 将枚举转换成Array
         * @returns {[]}
         */
        Object.assign(enumModel, {
            list(sortField = 'value') {
                const list = [...Object.values(originEnum)];
                return list.sort((a, b) => {
                    if (a?.[sortField] == null) {
                        return -1;
                    }

                    if (b?.[sortField] == null) {
                        return 1;
                    }

                    return String(a?.[sortField]).localeCompare(b?.[[sortField]]);
                });
            }
        });
    }
});

// const modulesFiles = require.context('./modules', true, /.js$/);
// const modules = modulesFiles.keys().reduce((modules, modulePath) => {
//     const moduleName = modulePath.replace(/^.\/(.*)\.js/, '$1');
//     const value = modulesFiles(modulePath);
//     modules[moduleName] = value.default;
//     return modules;
// }, {});

// console.log(modules);

export {
    addMinusStatusEnum,
    customInsuranceEnum,
    housePlaceEnum,
    sexEnum,
    jobStatusEnum,
    socialTypeEnum,
    socialTypeStatus,
    insuranceFundFileProcessStatusEnum,
    insuranceFundFileProcessStatus,
    insuranceFundFileSocialStatusEnum,
    insuranceFundFileSocialStatus,
    feedbackReceiveEnum,
    feedbackReceiveStatus,
    feedbackHandleEnum,
    feedbackHandleStatus,
    feedbackProblemTypeEnum,
    feedbackProblemType,
    feedbackAssignTypeEnum,
    feedbackAssignType,
    feedbackAutoAssignTypeEnum,
    feedbackAutoAssignType,
    feedbackBusiTypeEnum,
    feedbackBusiType,
    logBusiUnitEnum,
    logBusiUnit,
    decimalTypeStatus,
    baseTypeStatus,
    insuranceBaseTypeEnum,
    decimalTypeEnum,
    cpfSubmissionStatusEnum,
    cpfSubmissionStatus,
    cpfFormulaType,
    cpfFormulaTypeEnum
};
